package com.cswangdao.service.impl;

import com.cswangdao.domain.dto.KeywordPageDTO;
import com.cswangdao.domain.model.MarketKeyword;
import com.cswangdao.mapper.MarketKeywordMapper;
import com.cswangdao.result.PageResult;
import com.cswangdao.service.KeywordService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
@Transactional
public class KeywordServiceImpl implements KeywordService {
    @Autowired
    private MarketKeywordMapper keywordMapper;
    @Override
    public PageResult<MarketKeyword> pageQueryInfo(KeywordPageDTO pageDTO) {
        PageHelper.startPage(pageDTO.getPage(),pageDTO.getLimit());
        Page<MarketKeyword> page = keywordMapper.pageQueryInfo(pageDTO);
        PageResult<MarketKeyword> result = PageResult.result(page);
        return result;
    }

    @Override
    public void addKeyword(MarketKeyword keyword) {
        keyword.setAddTime(new Date());
        keyword.setUpdateTime(new Date());
        keywordMapper.addKeyword(keyword);
    }

    @Override
    public void updateById(MarketKeyword keyword) {
        keywordMapper.updateById(keyword);
    }

    @Override
    public void deleteById(Integer id) {
        keywordMapper.deleteById(id);
    }
}
